﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for ClassBusiness
/// </summary>
public class ClassBusiness
{
	public ClassBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool Insert(ClassEntities item)
    {
        bool flat = false;
        string[] para = { "@className", "@classInfo", "@classFactor" };
        string[] values = { item._className,item._classInfo,item._classFactor.ToString() };
        if (DataAccess.getExecProcedure("sp_InsertClass", para, values) > 0)
        {
            flat = true;
        }
        else
            flat = false;
        return flat;
    }

    public bool Edit(ClassEntities item)
    {
        bool flat = false;
        string[] para = { "@classID", "@className", "@classInfo", "@classFactor" };
        string[] values = { item._classID.ToString(),item._className, item._classInfo,item._classFactor.ToString() };
        if (DataAccess.getExecProcedure("sp_UpdateClass", para, values) > 0)
            flat = true;
        else
            flat = false;
        return flat;
    }

    public bool Delete(ClassEntities item)
    {
        if (DataAccess.getExecProcedure("sp_DeleteClass", new string[] { "@classID" }, new string[] { item._classID.ToString() }) > 0)
            return true;
        else
            return false;
    }

    public DataTable getAllClass()
    {
        return DataAccess.DataTable_Query("exec sp_GetAllClass '0'");
    }

    public ClassEntities getClass(int id)
    {
        DataTable dt = DataAccess.DataTable_Query("exec sp_GetAllClass '"+id+"'");
        ClassEntities ce = new ClassEntities();
        if (dt != null)
        {
            DataRow dr = dt.Rows[0];
            ce._classID = int.Parse(dr["classID"].ToString());
            ce._className = dr["className"].ToString();
            ce._classInfo = dr["classInfo"].ToString();
            ce._classFactor = Convert.ToDouble(dr["classFactor"].ToString());
        }
        return ce;
    }

    public DataTable getClassBy(string[] TableName, string[] fields, string Criterias, string priorities)
    {
        DataTable dt = new DataTable();
        string query = SQLQuery.SQLQuery_SELECT(TableName, fields, Criterias, priorities);
        return dt = DataAccess.DataTable_Query(query);
    }
}